# coding: utf-8
import ldap3
from ldap3 import Server, Connection, ALL, NTLM

# 'ldap3.core.exceptions'
base_dn = 'dc=VDIN,dc=local'
ZUO_DN = 'CN=左小宝,OU=云计算中心,dc=VDIN,dc=local'
TEST_DN = 'CN=果然可以,OU=云计算中心,DC=VDIN,DC=local'
server = Server('10.33.64.30', 389, get_info=ALL)
# conn = Connection(server, user="VDIN\\zuoxiaobao", password='Q@123123', authentication=NTLM)
conn = Connection(server, user="VDIN\\mantis", password='123456', authentication=NTLM)
# conn = Connection(server, TEST_DN, password='123456')
b_result = conn.bind()
conn.start_tls()
if b_result:
    result = conn.search(base_dn, '(sAMAccountName=chenyijun)', attributes=['*'])
    # result = conn.search(base_dn, '(cn=无证服务收费)', attributes=['*'])
    if result:
        print(conn.entries)
        USER_DN = 'CN=果然可以,OU=云计算中心,DC=VDIN,DC=local'
        # a = ldap3.extend.microsoft.modifyPassword.ad_modify_password(conn, ZUO_DN, 'Q@123123', None, controls=None)
        # print(a)
    else:
        print(conn.result)
else:
    print(conn.result)
